package com.cqie.hospitalescort.controller;

import com.cqie.hospitalescort.entity.City;
import com.cqie.hospitalescort.model.Result;
import com.cqie.hospitalescort.service.CityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 基础表-省市区 前端控制器
 * </p>
 *
 * @author gdy
 * @since 2025-02-18
 */
@RestController
@RequestMapping("/city")
@Api(value = "地址管理", tags = {"地址管理"})
public class CityController extends BaseController {

    @Autowired
    private CityService cityService;

    @GetMapping("")
    @ApiOperation(value = "三级地址")
    public Result<List<City>> getAddresses(@RequestParam(required = false) Integer parentId) {
        if (parentId == null) {
            parentId = 0;
        }

        return response(cityService.getChildrenByParentId(parentId));
    }

}
